package com.crypto;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import com.crypto.oauth.CryptoOAuthClient;
import com.crypto.ui.action.ClientLoginAction;
import com.crypto.ui.action.GetContactsAction;
import com.crypto.ui.components.BoxPanel;

public class HomePage extends WebPage {
	
	private static final long serialVersionUID = 1L;
	
	@SuppressWarnings("unused")
	private String clientLoginResponse = "";
	
	@SuppressWarnings("unused")
	private String userContacts = "";
	
	@SuppressWarnings("unused")
	private String accessToken = "";
	
    public HomePage(final PageParameters parameters) {
		
    	final CryptoOAuthClient client = new CryptoOAuthClient();
    	
    	add(new FeedbackPanel("feedback"));
    	
    	add(new BoxPanel(
    			"client-login", 
    			"1. El cliente se loguea", 
    			"<ul><li>http://localhost:8080/CryptoOAuthServer/oauth/token?grant_type=client_credentials&client_id=clientId&client_secret=clientSecret</li></ul>", 
    			"Access Tocken", 
    			new ClientLoginAction()
    		)
    	);
    	
    	BoxPanel approveClient = new BoxPanel(
    			"approve-client", 
    			"2. El cliente solicita autorización del usuario", 
    			"<ul><li>http://localhost:8080/CryptoOAuthServer/oauth/authorize?client_id=clientId&redirect_uri=http://localhost:9090/&response_type=code &scope=read</li></ul>", 
    			"Authorization Code", 
    			new ExternalLink("box-panel-action", client.getAuthorizationCodeRequestUrl()
    		)
    	);
    	add(approveClient);
    	
    	String authorizationCode = parameters.get("code").toString();
   		approveClient.setActionResponseText(authorizationCode);
    	
    	add(new BoxPanel(
    			"get-contacts", 
    			"3. El cliente solicita el Access Token y obtiene los contactos del usuario", 
    			"<ul><li>http://localhost:8080/CryptoOAuthServer/oauth/authorize?grant_type=authorization_code&client_id=clientId&client_secret=clientSecret &code=Jh8Mx6&redirect_uri=http://localhost:9090/&scope=read</li><li>http://localhost:8080/CryptoOAuthServer/contact/jsonListForUser/2</li></ul>", 
    			"Contactos", 
    			new GetContactsAction(authorizationCode)
    		)
    	);
    }
    
}
